<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="公众号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jwid">
              <a-input v-model="model.jwid" placeholder="请输入公众号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="应用类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationType">
              <a-input v-model="model.applicationType" placeholder="请输入应用类型"  ></a-input>
            </a-form-model-item>
          </a-col> -->
         
          <a-col :span="12">
            <a-form-model-item label="微信号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinNumber">
              <a-input v-model="model.weixinNumber" placeholder="请输入微信号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="微信AppId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinAppid">
              <a-input v-model="model.weixinAppid" placeholder="请输入微信AppId"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="微信AppSecret" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinAppsecret">
              <a-input v-model="model.weixinAppsecret" placeholder="请输入微信AppSecret"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="菜单域名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinAppsecret">
              <a-input v-model="model.hdUrl" placeholder="请输入菜单域名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="公众号类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountType">
              <j-dict-select-tag type="list" v-model="model.accountType" dictCode="jw_account_type" placeholder="请选择公众号类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否认证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authStatus">
              <j-dict-select-tag type="list" v-model="model.authStatus" dictCode="yn" placeholder="请选择是否认证" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="Access_Token" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accessToken">
              <a-input v-model="model.accessToken" placeholder="请输入Access_Token"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="微信商户号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinMchid">
              <a-input v-model="model.weixinMchid" placeholder="请输入微信商户号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="APIv3密钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinMchkey">
              <a-input v-model="model.weixinMchkey" placeholder="请输入APIv3密钥"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="平台证书序列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mchSerialNo">
              <a-input v-model="model.mchSerialNo" placeholder="请输入证书序列号"  ></a-input>
            </a-form-model-item>
          </a-col>
          
           <a-col :span="12">
            <a-form-model-item label="微信API证书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mchkeyPath">  
              <a-textarea :rows="5" v-model="model.mchkeyPath" />         
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="微信平台证书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mchcertPath">             
              <a-textarea :rows="5" v-model="model.mchcertPath" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="微信API证书路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mchkeyPath">
              <j-upload v-model="model.mchkeyPath"></j-upload>           
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="微信平台证书路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mchcertPath">             
              <j-upload v-model="model.mchcertPath"></j-upload>   
            </a-form-model-item>
          </a-col> -->
          
          <a-col :span="12">
            <a-form-model-item label="微信二维码图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qrcodeimg">
              <j-image-upload  v-model="model.qrcodeimg" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="token获取的时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tokenGettime">
              <j-date placeholder="请选择token获取的时间"  v-model="model.tokenGettime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="api凭证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiticket">
              <a-input v-model="model.apiticket" placeholder="请输入api凭证"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="apiticket获取时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiticketGettime">
              <j-date placeholder="请选择apiticket获取时间"  v-model="model.apiticketGettime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="jsapiticket" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jsapiticket">
              <a-input v-model="model.jsapiticket" placeholder="请输入jsapiticket"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="jsapiticket获取时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jsapiticketGettime">
              <j-date placeholder="请选择jsapiticket获取时间"  v-model="model.jsapiticketGettime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="类型：1手动授权，2扫码授权" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authType">
              <j-dict-select-tag type="list" v-model="model.authType" dictCode="jw_auth_type" placeholder="请选择类型：1手动授权，2扫码授权" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="功能的开通状况：1代表已开通" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessInfo">
              <a-textarea v-model="model.businessInfo" rows="4" placeholder="请输入功能的开通状况：1代表已开通" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="公众号授权给开发者的权限集" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="funcInfo">
              <a-textarea v-model="model.funcInfo" rows="4" placeholder="请输入公众号授权给开发者的权限集" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权方昵称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nickName">
              <a-input v-model="model.nickName" placeholder="请输入授权方昵称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权方头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="headimgurl">
              <a-input v-model="model.headimgurl" placeholder="请输入授权方头像"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authorizationInfo">
              <a-textarea v-model="model.authorizationInfo" rows="4" placeholder="请输入授权信息" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="刷新token" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authorizerRefreshToken">
              <a-input v-model="model.authorizerRefreshToken" placeholder="请输入刷新token"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="令牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="token">
              <a-input v-model="model.token" placeholder="请输入令牌"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权状态（1正常，2已取消）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authorizationStatus">
              <j-dict-select-tag type="list" v-model="model.authorizationStatus" dictCode="jw_auth_status" placeholder="请选择授权状态（1正常，2已取消）" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="微信商户号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinMchid">
              <a-input v-model="model.weixinMchid" placeholder="请输入微信商户号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="微信商户号KEY" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinMchkey">
              <a-input v-model="model.weixinMchkey" placeholder="请输入微信商户号KEY"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JwWebJwidForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           jwid: [
              { required: true, message: '请输入公众号!'},
           ],
           name: [
              { required: true, message: '请输入名称!'},
           ],
           weixinAppid: [
              { required: true, message: '请输入微信AppId!'},
           ],
           weixinAppsecret: [
              { required: true, message: '请输入微信AppSecret!'},
           ],
           accountType: [
              { required: true, message: '请输入公众号类型!'},
           ],
           authStatus: [
              { required: true, message: '请输入是否认证!'},
           ],
        },
        url: {
          add: "/mp/jwWebJwid/add",
          edit: "/mp/jwWebJwid/edit",
          queryById: "/mp/jwWebJwid/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>